﻿using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Entity.Print;
using Coldairarrow.IBusiness.PS;
using Coldairarrow.Util;
using Coldairarrow.Util.ClassLibrary;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Coldairarrow.Api.Controllers.PS
{
    [Route("/PS/[controller]/[action]")]
    public class PrintServiceController : BaseApiController
    {
        private readonly RedisOptions _redisOptions;
        private readonly MongoDBOptions _mongodbOptions;

        #region DI

        public PrintServiceController(IPrintServiceBusiness pPrintServiceBus, IOptions<MongoDBOptions> mongodbOptions, IOptions<RedisOptions> redisOptions)
        {
            _pPrintServiceBus = pPrintServiceBus;
            _mongodbOptions = mongodbOptions.Value;
            _redisOptions = redisOptions.Value;
        }

        IPrintServiceBusiness _pPrintServiceBus { get; }
        #endregion


        /// <summary>
        /// 按批次获取待打印列表
        /// </summary>
        /// <param name="printer">打印机ID</param>
        /// <returns></returns>
        [HttpPost]
        [NoCheckJWT]
        public async Task<List<PrintQueue>> GetBatchList(string printer)
        {
            return await _pPrintServiceBus.GetBatchListAsync(printer, _mongodbOptions, _redisOptions);
        }
        /// <summary>
        /// 按月份分页返回历史打印队列
        /// </summary>
        /// <param name="year">四字符的年份</param>
        /// <param name="month">月份</param>
        /// <param name="startDay">开始日</param>
        /// <param name="endDay">结束日</param>
        /// <param name="keyword">收货单号、物料编码、名称、规格和批次</param>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageSize">每页记录数</param>
        /// <returns>分页历史打印队列</returns>
        [HttpPost]
        [NoCheckJWT]
        public List<HistoryPrintQueueDTO> GetHistoryBatchList(string year="", string month="", int startDay=1, int endDay=0, string keyword="", int pageIndex=1, int pageSize=50)
        {
            return _pPrintServiceBus.GetHistoryBatchList(_mongodbOptions,year,month, startDay, endDay,keyword,pageIndex, pageSize);
        }
        /// <summary>
        /// 按条件分页返回历史打印队列总页数
        /// </summary>
        /// <param name="year">年份</param>
        /// <param name="month">月份</param>
        /// <param name="startDay">上限日</param>
        /// <param name="endDay">下限日</param>
        /// <param name="keyword">收货单号、物料编码、名称、规格和批次</param>
        /// <param name="pageSize">每页记录数</param>
        /// <returns>总页数</returns>
        [HttpPost]
        [NoCheckJWT]
        public int GetTotalPageCount(string year = "", string month = "", int startDay = 1, int endDay = 0, string keyword = "",int pageSize = 50)
        { 
             return _pPrintServiceBus.GetTotalPageCount(_mongodbOptions,year,month, startDay, endDay,keyword,pageSize);           
        }
    }

}
